package com.example.oauthserver.repository;

import com.example.oauthserver.model.RoleDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleRepository extends JpaRepository<RoleDO,Integer> {
    @Query(value = "select new com.example.oauthserver.model.RoleDO(r.name) from Role r left join UserRole ur on r.id = ur.roleId where ur.userId = :id")
    List<RoleDO> findByRoleId(@Param("id") final Integer id);
}
